<template>
  <base-breadcrumb
    :title="title"
    v-loading="loading2"
  >
    <a-card class="mb20">
      <titleName>验收资料<span
          v-if="!disabled"
          class="red"
          style="font-size: 14px;font-weight: normal;"
        >（所有单位名称须填写全称）</span></titleName>
      <a-form-model
        ref="ruleForm"
        :rules="rules"
        :model="form"
        :labelCol="{ lg: { span: 6 }, sm: { span: 6 } }"
        :wrapperCol="{ lg: { span: 16 }, sm: { span: 16 } }"
      >
        <a-row :gutter="24">
                    <a-col
                      :md="16"
                      :sm="16"
                    >
                      <a-form-model-item
                        label="所属单位："
                        prop="projectId"
                      >
                        <org-tree-select
                           is-auto-select-first
                           is-need-auth
                           check-strictly
                           :is-query-projec-detail="false"
                           :disabled="pageType === 'look'"
                           :status-set="pageType === 'look' ? [1,2,3,4,5,6]: [1,2,3]"
                          v-model="form.projectId"
                           @select="selectOrg"
                        ></org-tree-select>
                      </a-form-model-item>
                    </a-col>
<!--          <a-col-->
<!--            :md="8"-->
<!--            :sm="8"-->
<!--          >-->
<!--            <a-form-model-item-->
<!--              label="所属分公司："-->
<!--              prop="branchComId"-->
<!--            >-->
<!--              <b-input-->
<!--                v-if="pageType === 'look'"-->
<!--                disabled-->
<!--                v-model="form.branchComName"-->
<!--              />-->
<!--              <SelectSubCompany-->
<!--                v-else-->
<!--                placeholder="请选择"-->
<!--                v-model="form.branchComId"-->
<!--              ></SelectSubCompany>-->
<!--            </a-form-model-item>-->
<!--          </a-col>-->
<!--          <a-col-->
<!--            :md="8"-->
<!--            :sm="8"-->
<!--          >-->
<!--            <a-form-model-item-->
<!--              label="所属项目："-->
<!--              prop="projectId"-->
<!--            >-->
<!--              <b-input-->
<!--                v-if="pageType === 'look'"-->
<!--                disabled-->
<!--                v-model="form.projectName"-->
<!--              />-->
<!--              <SelectProject-->
<!--                v-else-->
<!--                placeholder="请选择"-->
<!--                v-model="form.projectId"-->
<!--                :form="form"-->
<!--                :isClear="id == ''"-->
<!--                keyValue="branchComId"-->
<!--                @change="getOrganizePeopleList()"-->
<!--              ></SelectProject>-->
<!--            </a-form-model-item>-->
<!--          </a-col>-->
          <a-col
            :md="8"
            :sm="8"
          >
            <a-form-model-item
              label="是否自有/自租："
              prop="ownOrRent"
            >
              <a-radio-group
                :disabled="disabled"
                v-model="form.ownOrRent"
                @change="ownOrRentChange"
              >
                <a-radio :value="true">
                  是
                </a-radio>
                <a-radio :value="false">
                  否
                </a-radio>
              </a-radio-group>
            </a-form-model-item>
          </a-col>
          <a-col
            :md="8"
            :sm="8"
          >
            <a-form-model-item
              label="设备编号（物资编码）"
              prop="materialCode"
            >
              <BSelect
                v-if="form.ownOrRent"
                :disabled="disabled"
                v-model="form.materialCode"
                :request="e=>getMaterialList({pageSize:10000,pageNo:1,auditStatus:'PAST',baseId:this.form.id})"
                :keys="['id','materialCode']"
                @selectChange="selectMaterialCode"
                @change2="materialCodeChange"
              />
              <BaseInput
                v-else
                :disabled="disabled"
                placeholder="请输入"
                v-model="form.materialCode"
              ></BaseInput>
            </a-form-model-item>
          </a-col>
          <a-col
            :md="8"
            :sm="8"
          >
            <a-form-model-item
              label="规格型号"
              prop="specModel"
            >
              <BaseInput
                :disabled="disabled"
                placeholder="请输入"
                v-model="form.specModel"
              ></BaseInput>
            </a-form-model-item>
          </a-col>
          <a-col
            :md="8"
            :sm="8"
          >
            <a-form-model-item
              label="产权单位"
              prop="propertyUnit"
            >
              <BaseInput
                :disabled="disabled"
                placeholder="请输入"
                v-model="form.propertyUnit"
              ></BaseInput>
            </a-form-model-item>
          </a-col>
          <a-col
            :md="8"
            :sm="8"
          >
            <a-form-model-item
              label="安装单位"
              prop="installUnit"
            >
              <BaseInput
                :disabled="disabled"
                placeholder="请输入"
                v-model="form.installUnit"
              ></BaseInput>
            </a-form-model-item>
          </a-col>
          <a-col
            :md="8"
            :sm="8"
          >
            <a-form-model-item
              label="生产厂家"
              prop="manufacturer"
            >
              <BaseInput
                :disabled="disabled"
                placeholder="请输入"
                v-model="form.manufacturer"
              ></BaseInput>
            </a-form-model-item>
          </a-col>
          <a-col
            :md="8"
            :sm="8"
          >
            <a-form-model-item
              label="进场日期"
              prop="entryTime"
            >
              <a-date-picker
                valueFormat="YYYY-MM-DD"
                :disabled="disabled"
                placeholder="请输入"
                v-model="form.entryTime"
              ></a-date-picker>
            </a-form-model-item>
          </a-col>
        </a-row>
      </a-form-model>
    </a-card>

    <a-card>
      <titleName title="安监补充资料"></titleName>
      <a-form-model
        ref="addRuleForm"
        :rules="addRules"
        :model="form"
        :labelCol="{ lg: { span: 6 }, sm: { span: 6 } }"
        :wrapperCol="{ lg: { span: 16 }, sm: { span: 16 } }"
      >
        <a-row :gutter="24">
          <a-col
            :md="8"
            :sm="8"
          >
            <a-form-model-item
              label="设备类型"
              prop="equipTypeId"
            >
              <BSelect
                :disabled="disabled"
                v-model="form.equipTypeId"
                :request="e=>getTypeLabel(13)"
                :keys="['id','name']"
                @selectChange="form.equipmentClass = $event.code"
              />
            </a-form-model-item>
          </a-col>
          <a-col
            :md="8"
            :sm="8"
          >
            <a-form-model-item label="设备分类">
              <BSelect
                v-model="form.equipmentClass"
                disabled
                placeholder="请输入"
                :list="[
                {id:'0',name:'一类'},
                {id:'1',name:'二类'},
                {id:'2',name:'三类'},
              ]"
              />
            </a-form-model-item>
          </a-col>
          <a-col
            :md="8"
            :sm="8"
          >
            <a-form-model-item label="出厂日期">
              <a-date-picker
                valueFormat="YYYY-MM-DD"
                :disabled="disabled"
                placeholder="请输入"
                v-model="form.appearanceDate"
              ></a-date-picker>
            </a-form-model-item>
          </a-col>
          <a-col
            :md="8"
            :sm="8"
          >
            <a-form-model-item label="设备编码">
              <BaseInput
                :disabled="disabled"
                placeholder="请输入"
                v-model="form.equipCode"
              ></BaseInput>
            </a-form-model-item>
          </a-col>
          <a-col
            :md="8"
            :sm="8"
          >
            <a-form-model-item label="使用登记证">
              <BaseInput
                :disabled="disabled"
                placeholder="请输入"
                v-model="form.recordNum"
              ></BaseInput>
            </a-form-model-item>
          </a-col>
          <a-col
            :md="8"
            :sm="8"
          >
            <a-form-model-item label="合格证号">
              <BaseInput
                :disabled="disabled"
                placeholder="请输入"
                v-model="form.certNum"
              ></BaseInput>
            </a-form-model-item>
          </a-col>
          <a-col
            :md="8"
            :sm="8"
          >
            <a-form-model-item label="责任人">
              <a-select
                :disabled="disabled"
                placeholder="请选择"
                v-model="form.respEmployeeId"
              >
                <a-spin
                  v-if="fetchingOrganizePeopleList"
                  slot="notFoundContent"
                  size="small"
                />
                <a-select-option
                  v-for="i in organizePeopleList"
                  :key="i.employeeId"
                  :value="i.employeeId"
                >{{ i.employeeName }}
                </a-select-option>
              </a-select>
            </a-form-model-item>
          </a-col>
          <a-col
            :md="8"
            :sm="8"
          >
            <a-form-model-item label="验收情况">
              <BaseInput
                :disabled="disabled"
                placeholder="请输入"
                v-model="form.acceptanceInfo"
              ></BaseInput>
            </a-form-model-item>
          </a-col>
          <a-col
            :md="8"
            :sm="8"
          >
            <a-form-model-item label="检测报告编号">
              <BaseInput
                :disabled="disabled"
                placeholder="请输入"
                v-model="form.testReportNum"
              ></BaseInput>
            </a-form-model-item>
          </a-col>
          <a-col
            :md="8"
            :sm="8"
          >
            <a-form-model-item label="使用状态">
              <BSelect
                :disabled="disabled"
                v-model="form.equipStatusId"
                :request="e=>getTypeLabel(31)"
                :keys="['id','name']"
              />
            </a-form-model-item>
          </a-col>
        </a-row>
      </a-form-model>
    </a-card>

    <a-card class="mb20">
      <titleName title="相关资料上传"></titleName>
      <a-table
        bordered
        :columns="fileColumns"
        :data-source="uploadFiles"
      >
        <span
          slot="serial"
          slot-scope="text, record, index"
        >{{ index + 1 }}</span>
        <template
          slot="files"
          slot-scope="text, record"
        >
          <BFilePreview
            :disabled="disabled"
            :list.sync="record.files"
          />
        </template>
        <template
          slot="action"
          slot-scope="text, record"
          v-if="!disabled"
        >
          <a v-upload="{
            type:'image',
            mult:true,
            limitText:9,
            limit:()=>{return 9-record.files.length},
            cb:e=>uploadFile(record,e),
            record:record,
            loading:'loading2',
            businessCode:'SHE04'
          }">
            <u>照片上传</u></a>
          <span
            class="red"
            v-if="record.need"
          >(必传)</span>
        </template>
      </a-table>
    </a-card>

    <!-- 维修保养记录表 -->
    <a-card
      class="mb20"
      v-if="form.itemVO && form.itemVO.length > 0"
    >
      <titleName title="维修记录"></titleName>
      <s-table
        ref="table"
        bordered
        size="default"
        rowKey="key"
        :columns="maintenanceRecord"
        :data="maintenanceRecordData"
        :alert="true"
        show-size-changer
        show-quick-jumper
        :showPagination="false"
      >
        <span
          slot="serial"
          slot-scope="text, record, index"
        >{{ index + 1 }}</span>
        <template
          slot="fileList"
          slot-scope="text, record"
        >
          <BFilePreview
            :disabled="true"
            :list.sync="record.fileInfoList"
          />
        </template>
      </s-table>
    </a-card>
    <div class="tool-btns page-btn-right-top">
      <template v-if="!disabled">
        <!--        <a-button-->
        <!--          type="primary"-->
        <!--          v-if="form.auditStatus != 'SUBMITTED'"-->
        <!--          :loading="loading.DRAFT"-->
        <!--          @click="handleSave('DRAFT')"-->
        <!--        >保存-->
        <!--        </a-button>-->
        <a-button
          type="primary"
          :loading="loading.SUBMITTED"
          @click="handleSave('SUBMITTED')"
        >提交</a-button>
      </template>
      <a-button
        type="primary"
        @click="handleClose"
      >关闭</a-button>
    </div>
  </base-breadcrumb>
</template>
<script>
import SelectSubCompany from '@/components/Select/SelectSubCompany' // 分公司
import SelectProject from '@/components/Select/SelectProject' // 分公司
import { getSelectListByType } from '@/api/safetySupervision/common.js'
import { getOrganizePeopleList } from '@/api/safetySupervision/emergencyDrill'
import UploadList from '@/components/UploadList'
import { getEquipmentDetail, deleteEquipment, updateEquipment, addEquipment, getEquipmentManagemenList, getMaterialList } from '@/api/safetySupervision/equipmentManagement'
import BFilePreview from '@/components/BComponents/BFilePreview'

const columns = [
  {
    title: '序号',
    dataIndex: 'serial',
    width: '5%',
    scopedSlots: { customRender: 'serial' }
  },
  {
    title: '文件名称',
    dataIndex: 'fileName',
    width: '40%'
  },
  {
    title: '文件格式',
    dataIndex: 'suffixName'
  },
  {
    title: '操作',
    dataIndex: 'action',
    width: '15%',
    scopedSlots: { customRender: 'action' }
  }
]
const maintenanceRecord = [
  {
    title: '序号',
    dataIndex: 'serial',
    width: '5%',
    scopedSlots: { customRender: 'serial' }
  },
  {
    title: '维保类型',
    dataIndex: 'maintenanceName'
  },
  {
    title: '维修/保养人',
    dataIndex: 'employeeName'
  },
  {
    title: '维保时间',
    dataIndex: 'maintenanceDate'
  },
  {
    title: '维保内容',
    dataIndex: 'content',
    width: '30%'
  },
  {
    title: '文件',
    dataIndex: 'fileList',
    width: '40%',
    scopedSlots: { customRender: 'fileList' }
  }
]
import { STable } from '@/components'
import { Item } from 'ant-design-vue/es/vc-menu'
import Vue from 'vue'
import { deviceList } from '@/api/material/acceptance/device'
import { uploadFile } from '@/api'

export default {
  name: 'a' + Date.now(),
  components: {
    SelectSubCompany,
    SelectProject,
    STable,
    UploadList,
    BFilePreview
  },
  data() {
    return {
      title: '新增设备',
      getMaterialList,
      columns,
      loading2: false,
      loading: {
        DELETE: false,
        DRAFT: false,
        SUBMITTED: false
      },
      fetchingOrganizePeopleList: false,
      fetchingEquipmentClassification: false,
      fetchingStateClassification: false,
      maintenanceRecord,

      loadData: (parameter) => {
        const requestParameters = Object.assign({}, parameter, this.queryParam)
        return new Promise((resolve, reject) => {
          resolve({
            data: this.form.fileInfoList
          })
        })
      },
      getTypeLabel: async (type) => {
        const [err, res] = await getSelectListByType({ pageSize: 10000, pageNo: 1, type })
        if (err) return { code: 500 }
        else {
          res.data.map((v) => {
            v.disabled = !v.enabled
          })
          return { code: this.SUCCESS_CODE, ...res }
        }
      },
      maintenanceRecordData: (parameter) => {
        const requestParameters = Object.assign({}, parameter, this.queryParam)
        return new Promise((resolve, reject) => {
          resolve({
            data: this.form.itemVO
          })
        })
      },
      rules: {
        branchComId: [{ required: true, message: '请选择分公司' }],
        projectId: [{ required: true, message: '请选择所属项目' }],
        materialCode: [{ required: true, message: '请输入设备编号（物资编码）' }],
        name: [{ required: true, message: '请输入设备名称' }],
        specModel: [{ required: true, message: '请输入规格型号' }],
        propertyUnit: [{ required: true, message: '请输入产权单位' }],
        installUnit: [{ required: true, message: '请输入安装单位' }],
        manufacturer: [{ required: true, message: '请输入生产厂家' }],
        entryTime: [{ required: true, message: '请选择进场日期' }]
      },
      addRules: {
        equipTypeId: [{ required: true, message: '请选择设备类型' }],
        equipStatusId: [{ required: true, message: '请选择设备状态' }],
        equipCode: [{ required: true, message: '请选择设备状态' }]
      },

      form: {
        id: null,
        equipType: {},
        equipStatus: {},
        fileInfoList: [],
        ownOrRent: true,
        materialCode: undefined,
        propertyUnit: '',
        specModel: '',
        installUnit: '',
        manufacturer: '',
        entryTime: this.$dateFormat(Date.now(), 'D')
      },
      uploadFiles: [
        // { fileName: '产权单位资质', files: [], need: true },
        // { fileName: '安装单位资质', files: [], need: true },
        { fileName: '设备合格证', files: [], need: false },
        { fileName: '使用登记证', files: [], need: false },
        { fileName: '安装验收/四方验收', files: [], need: false },
        { fileName: '第三方检测报告', files: [], need: false },
        { fileName: '其他', files: [], need: false }
      ],
      fileColumns: [
        { title: '序号', dataIndex: 'serial', width: 70, scopedSlots: { customRender: 'serial' } },
        { title: '文件名称', dataIndex: 'fileName', width: 150 },
        { title: '文件', dataIndex: 'files', scopedSlots: { customRender: 'files' } },
        { title: '操作', dataIndex: 'action', width: 150, scopedSlots: { customRender: 'action' } }
      ],
      token: '',
      id: '',
      selectedRowKeys: [],
      equipmentClassification: [], //设备分类
      stateClassification: [], //状态分类
      organizePeopleList: [] //责任人
    }
  },
  created() {
    this.token = Vue.getAcloudProvider().getAccessToken()
    this.getSelectList('14') //设备状态
    this.getSelectList('13') //设备分类
    this.form.id = this.id = this.$route.query.id
    this.title = this.id == '' ? '新增设备' : '编辑设备'
    if (this.disabled) {
      this.title = '设备详情'
    }
    this.getEquipmentDetail()
    // if (this.$route.query.pageType == 'look') {
    //     this.columns.length = this.columns.length - 1
    //     console.log(this.columns)
    // }
  },
  directives: {
    upload: {
      inserted(el, binding, vnode) {
        let input = document.createElement('input')
        input.setAttribute('type', 'file')
        input.setAttribute('accept', '.jpg, .jpeg, .gif, .png')
        input.style.position = 'absolute'
        el.parentElement.style.position = 'relative'
        input.style.left = 0
        input.style.opacity = 0
        if (binding.value.mult) {
          input.setAttribute('multiple', 'true')
        }
        input.addEventListener('change', async (e) => {
          let that = vnode.context

          if (binding.value.limit) {
            if (e.target.files.length + binding.value.record.files.length > binding.value.limitText) {
              that.$message.error('最多只能上传' + binding.value.limitText + '个附件！')
            }
          }
          const list = [...binding.value.record.files, ...e.target.files].slice(0, binding.value.limitText)
          const rLength = binding.value.record.files.length
          const arr = rLength < list.length ? list.slice(rLength, list.length) : []
          for (let i = 0; i < arr.length; i++) {
            let info = arr[i]
            const { size } = info
            if (size / 1024 / 1024 > 500) {
              return that.$message.error('上传文件不可超出500M')
            }
            const type = info.fileType || info.type
            const isImg = type === 'image/jpg' || type === 'image/jpeg' || type === 'image/png' || type === 'image/gif'
            if (binding.value.type === 'image' && !isImg) {
              return that.$message.error('只能上传图片文件！')
            }
            if (binding.value.needChineseName) {
              let re = new RegExp('[\\u4E00-\\u9FFF]+', 'g')
              if (!re.test(info.file?.name)) {
                that.$confirm({
                  title: '提示',
                  content: '请修改附件的名称后重新上传',
                  okType: 'danger'
                })
                return
              }
            }

            const data = new FormData()
            data.append('file', info)
            data.append('businessCode', binding.value.businessCode)
            that[binding.value.loading] = true
            await uploadFile(data)
              .then((res) => {
                that[binding.value.loading] = false
                if (res.code === 200) {
                  if (binding.value) {
                    // res.data.name = res.data.fileName + res.data.suffixName
                    // res.data.url =
                    //   '/api/ycloud-file-center/oper/download?access_token=' +
                    //   Vue.getAcloudProvider().getAccessToken() +
                    //   '&fileId=' +
                    //   res.data.fileId
                    // res.data.uid = res.data.id
                    binding.value.cb(res.data)
                  }
                }
              })
              .catch((err) => {
                that[binding.value.loading] = false
              })
          }
        })
        el.parentElement.appendChild(input)
      }
    }
  },
  computed: {
    pageType() {
      return this.$route.query.pageType || 'look'
    },
    isDisabled() {
      return this.pageType == 'edit'
    },
    disabled() {
      return this.pageType === 'look'
    }
  },
  methods: {
    selectOrg(val) {
      this.form.branchComId = val[val.length - 2].orgId
      this.getOrganizePeopleList()
    },
    uploadFile(row, file) {
      row.files.push(file)
    },
    ownOrRentChange(e) {
      this.form.ownOrRent = e.target.value
      this.form.materialCode = undefined
      this.selectMaterialCode({})
    },
    materialCodeChange(e) {
      if (!e) {
        this.selectMaterialCode({})
      }
    },
    selectMaterialCode(e) {
      this.form.propertyUnit = e.supplier || '' //产权单位
      this.form.specModel = e.materialModel || '' //规格型号
      this.form.installUnit = e.installationUnit || '' //安装单位
      this.form.manufacturer = e.manufacturer || '' //生产厂家
    },
    delItem(idx) {
      this.form.fileInfoList.splice(idx, 1)
      this.$refs.table.refresh(true)
      console.log(this.form.fileInfoList)
    },
    async getEquipmentDetail() {
      const { id } = this.$route.query
      if (!id) return
      const params = { id }
      this.loading2 = true
      const [err, res] = await getEquipmentDetail(params)
      this.loading2 = false
      if (!err) {
        if (res.data.itemVO) {
          res.data.itemVO.forEach((item) => {
            item.maintenanceName = item.maintenanceType.name
            if (res.data.itemVO.fileInfoList == null) {
              res.data.itemVO.fileInfoList = []
            }
          })
        }

        // res.data.fileInfoList = res.data.fileList
        this.form = {
          ...this.form,
          ...res.data
        }
        this.form.equipmentClass = this.form.equipmentClass !== null ? this.form.equipmentClass + '' : ''

        // this.uploadFiles[0].files = this.form.assetsUnitFileList || [] //产权单位资质
        // this.uploadFiles[1].files = this.form.installUnitFileList || [] //安装单位资质
        this.uploadFiles[0].files = this.form.equipmentFileList || [] //设备合格证
        this.uploadFiles[1].files = this.form.useFileList || [] //使用登记证
        this.uploadFiles[2].files = this.form.checkFileList || [] //安装验收/四方验收
        this.uploadFiles[3].files = this.form.detectionFileList || [] //第三方检测报告
        this.uploadFiles[4].files = this.form.otherFileList || [] //其他

        // this.form.ownOrRent = this.form.ownOrRent !== null ? this.form.ownOrRent : true

        this.$refs.table && this.$refs.table.refresh(true)
        this.getOrganizePeopleList()
      }
    },
    // fileArrysData(e) {
    //     console.log
    //     this.form.fileInfoList = e;
    // },
    //获取项目下的人员列表
    getOrganizePeopleList() {
      if (!this.form.projectId) return
      let params = {
        id: this.form.projectId
      }
      this.fetchingOrganizePeopleList = true
      getOrganizePeopleList(params).then((res) => {
        this.fetchingOrganizePeopleList = false
        let obj = {}
        res.data = res.data.reduce((cur, next) => {
          obj[next.employeeId] ? '' : (obj[next.employeeId] = true && cur.push(next))
          return cur
        }, []) //设置cur默认类型为数组，并且初始值为空的数组

        this.organizePeopleList = res.data || []
      })
    },
    //获取设备状态
    async getSelectList(type) {
      this.fetchingEquipmentClassification = true
      this.fetchingStateClassification = true
      const [err, res] = await getSelectListByType({ type })
      if (!err) {
        if (type == '14') {
          this.fetchingEquipmentClassification = false
          this.equipmentClassification = res.data || []
        } else {
          this.fetchingStateClassification = false
          this.stateClassification = res.data || []
        }
      }
    },
    validateForm() {
      let flag = false
      this.$refs.ruleForm.validate((valid) => {
        flag = valid
        if(!valid) {
          this.$message.warning("请填写完所有必填项信息")
        }
      })
      return flag
    },
    validateAddForm() {
      let flag = false
      this.$refs.addRuleForm.validate((valid) => {
        flag = valid
        if(!valid) {
          this.$message.warning("请填写完所有必填项信息")
        }
      })
      return flag
    },
    fileArrysData: function (val) {
      this.form.fileInfoList = val
      this.$refs.table.refresh(true)
    },
    onSelectChange(e) {
      console.log(e)
    },
    async deleteEquipment(params) {
      const [err, res] = await deleteEquipment(params)
      if (!err) {
        this.$message.success('删除成功')
        this.handleClose()
      }
    },
    async isEquipCode() {
      const [err, res] = await getEquipmentManagemenList({ pageNo: 1, pageSize: 100000 })
      if (!err) {
        let list = res.data.filter((i) => i.equipCode == this.formInfo.equipCode)
        if (plan.length > 0) {
          this.$message.warning('设备编码重复')
          this.isSave = true
        } else {
          this.isSave = false
        }
      }
    },
    // 处理增、删、改操作
    async handleSave(status) {
      let result = true
      this.uploadFiles.map((v) => {
        if (v.need && v.files.length === 0) result = false
      })
      if (!result) {
        return this.$noticeWarning('请上传相关资料')
      }
      if (status !== 'DELETE' && !this.validateForm() && !this.validateAddForm()) return
      if (this.loading[status]) return

      // if (typeof this.form.entryTime != 'string') {
      //     this.form.entryTime = this.form.entryTime.format('YYYY-MM-DD HH:mm:ss')
      // }
      // if (typeof this.form.appearanceDate != 'string') {
      //     this.form.appearanceDate = this.form.appearanceDate.format('YYYY-MM-DD HH:mm:ss')
      // }

      const params = {
        ...this.form,
        auditStatus: status
      }
      // params.assetsUnitFile = this.uploadFiles[0].files//产权单位资质
      // params.installUnitFile = this.uploadFiles[1].files//安装单位资质
      params.equipmentFile = this.uploadFiles[0].files //设备合格证
      params.useFile = this.uploadFiles[1].files //使用登记证
      params.checkFile = this.uploadFiles[2].files //安装验收/四方验收
      params.detectionFile = this.uploadFiles[3].files //第三方检测报告
      params.otherFile = this.uploadFiles[4].files //其他

      const { pageType } = this.$route.query
      const fn = pageType === 'edit' ? updateEquipment : addEquipment
      const map = {
        DELETE: deleteEquipment,
        DRAFT: fn,
        SUBMITTED: fn
      }
      if (status == 'DELETE') {
        let that = this
        this.$confirm({
          title: '温馨提示',
          content: '确定是否删除数据？',
          okText: '确认',
          okType: 'danger',
          cancelText: '取消',
          onOk: () => {
            return that.deleteEquipment(params)
          }
        })
      } else {
        this.loading[status] = true
        const [err, res] = await map[status](params)
        if (!err) {
          this.$message.success('成功')
          this.handleClose()
        }
      }

      this.loading[status] = false
    },
    handleClose() {
      this.$multiTab.close(this.$route.fullpath)
      //  history.go(-1)
    }
  }
}
</script>
<style lang="less" scoped>
@deep: ~'>>>';
.tool-btns {
  display: flex;
  justify-content: flex-end;

  @{deep} .ant-btn + .ant-btn {
    margin-left: 12px;
  }
}

.row {
  display: flex;
  flex-direction: row;
}

.red {
  color: red;
}
</style>
